"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useWidgetView = useWidgetView;
var _vue = require("vue");
function useWidgetView(props) {
  const currWidget = (0, _vue.computed)(() => {
    const {
      renderParams
    } = props;
    return renderParams.widget;
  });
  const isEditMode = (0, _vue.computed)(() => {
    const {
      renderParams
    } = props;
    return renderParams.isEditMode || false;
  });
  const isViewMode = (0, _vue.computed)(() => {
    const {
      renderParams
    } = props;
    return renderParams.isViewMode || false;
  });
  const widgetOptions = (0, _vue.computed)(() => {
    const {
      renderParams
    } = props;
    const {
      widget
    } = renderParams;
    return widget ? widget.options : {};
  });
  const widgetModel = (0, _vue.computed)({
    get() {
      const {
        renderParams
      } = props;
      const {
        $formView,
        widget
      } = renderParams;
      return $formView ? $formView.getItemValue(widget) : null;
    },
    set(value) {
      const {
        renderParams
      } = props;
      const {
        $formView,
        widget
      } = renderParams;
      if ($formView) {
        $formView.setItemValue(widget, value);
      }
    }
  });
  return {
    currWidget,
    widgetOptions,
    widgetModel,
    isEditMode,
    isViewMode
  };
}